var infoModal = myApp.directive('infoModal', function() {
	return {
		restrict: 'EA',
		replace:true,
		scope: {
			msg: '=',
			visible: '='
		}, 
		template: 
			'<div class="modal" tabindex="-1" role="dialog">'+
				'<div class="modal-dialog modal-sm" role="document">'+
					'<div class="modal-content">'+
						'<div class="modal-header">'+
							'<button type="button" class="close" ng-click="hideModal()" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
	        				'<h3 class="modal-title">提示</h3>'+
						'</div>'+
						'<div class="modal-body">'+
							'<p class="text-center">{{msg}}</p>'+
						'</div>'+
						'<div class="modal-footer">'+
							'<button type="button" class="btn btn-primary" ng-click="hideModal()">确认</button>'+
						'</div>'+
					'</div>'+
				'</div>'+
			'</div>',
		link: function(scope, elem, attrs) {
			// 显示弹层
			scope.showModal = function(visible) {
				if(visible) {
					elem.modal('show');
				} else {
					elem.modal('hide');
				}
			};
			// 关闭弹层
			scope.hideModal = function () {
				scope.visible = false;
			}
			// 判断标志位visible变化
			if(!attrs.visible) {
                //The attribute isn't defined, show the modal by default
                scope.showModal(true);
            }
            else {
            	scope.$watch("visible", function (newValue, oldValue) {
                    scope.showModal(newValue);
                });
            }
		}
	}
})